﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class ToolSheetAudit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            SetData();
        }

    }

    public void SetData()
    {
        ConnectionStringSettings connObj = ConfigurationManager.ConnectionStrings["smsConnectionString"];
        string connectionString = connObj.ConnectionString;
        SqlConnection objConnection = new SqlConnection(connectionString);

        String query = "SELECT ToolSheetID, ToolsSerial AS 工具编号, ToolsName AS 工具名称, ToolsQuantity AS 数量 FROM ToolList where ToolSheetID = '" + Request.QueryString["ToolSheetID"] + "'";

        SqlDataAdapter da = new SqlDataAdapter(query, objConnection);

        DataSet ds = new DataSet();
        da.Fill(ds, "工具单");
        DataTable dt = ds.Tables["工具单"];
        DataView view = new DataView(dt);

        this.UltraWebGrid1.DataSource = view;
        this.UltraWebGrid1.DataKeyField = "ToolsSerial";
        this.UltraWebGrid1.DataBind();
        this.UltraWebGrid1.Columns[0].Hidden = true;
        /////////////////////////////////////////////////////////
        //ConnectionStringSettings connObj = ConfigurationManager.ConnectionStrings["smsConnectionString"];
        //string connectionString = connObj.ConnectionString;
        //SqlConnection objConnection = new SqlConnection(connectionString);
        //objConnection.Open();

        query = "select aspnet_Users.UserName AS 申请人,ConstructionCorp AS 施工单位,ProposeDate AS 申请日期,StartDate AS 开始日期,FinishDate AS 结束日期, DeptIdea AS 部门意见 " +
                "from ToolSheet inner join aspnet_Users on toolsheet.proposerid = aspnet_Users.UserId " +
                "Where ToolSheet.ToolSheetID = '" + Request.QueryString["ToolSheetID"] + "'";
        objConnection.Open();
        SqlCommand command = new SqlCommand(query, objConnection);
        SqlDataReader dr = command.ExecuteReader();
        if (dr.Read())
        {
            this.txtProposer.Text = dr["申请人"].ToString();
            this.txtApplicationDate.Text = dr["申请日期"].ToString();
            this.TxtConstructionCorp.Text = dr["施工单位"].ToString();
            this.StarDate.Text = dr["开始日期"].ToString();
            this.FinishDate.Text = dr["结束日期"].ToString();
            this.txtDeptComment.Text = dr["部门意见"].ToString();
        }
        dr.Close();
        objConnection.Close();

    }




    protected void Button1_Click(object sender, EventArgs e)
    {
        ToolApplicationDataSet ds = new ToolApplicationDataSet();
        ToolApplicationDataSet.ToolSheetDataTable tblToolsSheet = new ToolApplicationDataSet.ToolSheetDataTable();

        ToolApplicationDataSetTableAdapters.ToolSheetTableAdapter adapter = new ToolApplicationDataSetTableAdapters.ToolSheetTableAdapter();
        adapter.Fill(tblToolsSheet);

        String tsID = Request.QueryString["ToolSheetID"];
        //ToolApplicationDataSet.ToolSheetRow dr = ds.ToolSheet.FindByToolSheetID(Request.QueryString["ToolSheetID"]);
        ToolApplicationDataSet.ToolSheetRow dr = tblToolsSheet.FindByToolSheetID(Request.QueryString["ToolSheetID"]);
        //// find or create a new row to hold the data
  
        if (dr != null)
        {
            dr["AuditIdea"] = this.txtComment.Text;
            dr["AuditStatus"] = "拒绝";
            dr["AuditorID"] = Membership.GetUser().ProviderUserKey.ToString();
            dr["AuditingDate"] = System.DateTime.Now;
        }
        adapter.Update(dr);
        Response.Redirect("ToolSheetList.aspx");

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        ToolApplicationDataSet ds = new ToolApplicationDataSet();
        ToolApplicationDataSet.ToolSheetDataTable tblToolsSheet = new ToolApplicationDataSet.ToolSheetDataTable();

        ToolApplicationDataSetTableAdapters.ToolSheetTableAdapter adapter = new ToolApplicationDataSetTableAdapters.ToolSheetTableAdapter();
        adapter.Fill(tblToolsSheet);

        String tsID = Request.QueryString["ToolSheetID"];
        //ToolApplicationDataSet.ToolSheetRow dr = ds.ToolSheet.FindByToolSheetID(Request.QueryString["ToolSheetID"]);
        ToolApplicationDataSet.ToolSheetRow dr = tblToolsSheet.FindByToolSheetID(Request.QueryString["ToolSheetID"]);
        //// find or create a new row to hold the data

        if (dr != null)
        {
            dr["AuditIdea"] = this.txtComment.Text;
            dr["AuditStatus"] = "批准";
            dr["AuditorID"] = Membership.GetUser().ProviderUserKey.ToString();
            dr["AuditingDate"] = System.DateTime.Now;
        }
        adapter.Update(dr);
        Response.Redirect("ToolSheetList.aspx");
    }
}
